<?php

namespace WeForge;

use Illuminate\Contracts\Debug\ExceptionHandler;
use WeForge\Queue\Worker;

trait ConfiguresQueue
{
    /**
     * Ensure the queue / workers are configured.
     *
     * @return void
     */
    protected function ensureQueueIsConfigured()
    {
        if ($this->app->bound('queue.weforgeWorker')) {
            return;
        }

        $this->app->singleton('queue.weforgeWorker', function () {
            return new Worker(
                $this->app['queue'],
                $this->app['events'],
                $this->app[ExceptionHandler::class],
                function () {
                    return $this->app->isDownForMaintenance();
                }
            );
        });
    }
}
